package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.R;
import com.atguigu.spzx.model.vo.product.CategoryBrandVO;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/admin/product/categoryBrand")
@Tag(name = "分类品牌管理模块")
public class CategoryBrandController {
    @Resource
    CategoryBrandService categoryBrandService;
    @Operation(summary = "根据3级分类id查询分类下的所有品牌")
    @GetMapping("listBrandByC3id/{c3id}")
    public R listBrandByC3id(@PathVariable("c3id")Long c3id){
        List<Brand> list = categoryBrandService.listBrandByC3id(c3id);
        return R.ok("items" , list);
    }
    @Operation(summary = "条件查询分类品牌列表")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R list(@PathVariable("pageNum")Integer pageNum,
                  @PathVariable("pageSize")Integer pageSize,
                  CategoryBrand categoryBrand){
        PageInfo<CategoryBrandVO> pageInfo = categoryBrandService.list(pageNum,pageSize,categoryBrand);
        return R.ok("page" , pageInfo);
    }
    @Operation(summary = "新增分类品牌")
    @PostMapping("save")
    public R save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        //有些需求需要返回新增成功的角色对象给前端回显(需要绑定id)
        return R.ok();
    }
    @Operation(summary = "删除指定分类品牌")
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable("id") Long id){
        categoryBrandService.deleteByIds(Arrays.asList(id));
        return R.ok();
    }
    @Operation(summary = "查询指定分类品牌")
    @GetMapping("getById/{id}")
    public R getById(@PathVariable("id") Long id){
        CategoryBrand categoryBrand = categoryBrandService.getById(id);
        return R.ok("item",categoryBrand);
    }
    @Operation(summary = "更新指定分类品牌")
    @PutMapping("update")
    public R update(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.update(categoryBrand);
        //有些需求需要返回新增成功的角色对象给前端回显(需要绑定id)
        return R.ok();
    }

}
